package com.beidasoft.web.model.statisticalAnalysis;

import java.math.BigDecimal;
import java.util.Comparator;

/**
 * 全市案件数量统计 -- 排序操作
 * Created by Ronin on 2015/11/15.
 * Modified by songff on 2016-3-31
 */
public class CasesNumberSummarySort implements Comparator {
    //传一个排序标识
    private String sort;
    public CasesNumberSummarySort(String sort){
        this.sort = sort;
    }

    @Override
    public int compare(Object o1, Object o2) {
        CasesNumberSummary penaltyData1 = (CasesNumberSummary)o1;
        CasesNumberSummary penaltyData2 = (CasesNumberSummary)o2;
        if (sort.equals("01")){
            //按部门降序
            return sortDownByDepartment(penaltyData1, penaltyData2);
        }else if (sort.equals("02")){
            //按部门升序
            return sortUpByDepartment(penaltyData1, penaltyData2);
        }else if (sort.equals("21")){
            //按总案件量升序
            return sortUpByCaseCount(penaltyData1, penaltyData2);
        }else{
            //按总案件量降序
            return sortDownByCaseCount(penaltyData1, penaltyData2);
        }
    }

    //升序
    private int sortUpByDepartment(CasesNumberSummary o1, CasesNumberSummary o2) {
        String val1 = o1.getBmbh();
        String val2 = o2.getBmbh();

        if (val1.compareTo(val2) < 0) {
            return -1;
        } else if (val1.compareTo(val2) > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    private int sortUpByCaseCount(CasesNumberSummary o1, CasesNumberSummary o2) {
        BigDecimal val1 = o1.getAjzl();
        BigDecimal val2 = o2.getAjzl();

        if (val1.compareTo(val2) < 0) {
            return -1;
        } else if (val1.compareTo(val2) > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    //降序
    private int sortDownByDepartment(CasesNumberSummary o1, CasesNumberSummary o2) {
        String val1 = o1.getBmbh();
        String val2 = o2.getBmbh();

        if (val1.compareTo(val2) > 0) {
            return -1;
        } else if (val1.compareTo(val2) < 0) {
            return 1;
        } else {
            return 0;
        }
    }
    private int sortDownByCaseCount(CasesNumberSummary o1, CasesNumberSummary o2) {
        BigDecimal val1 = o1.getAjzl();
        BigDecimal val2 = o2.getAjzl();
        if (val1.compareTo(val2) > 0) {
            return -1;
        } else if (val1.compareTo(val2) < 0) {
            return 1;
        } else {
            return 0;
        }
    }
}
